<template>
  <div>
    <router-link tag="div" to="/" class="header-abs" v-if="isShow">
      <div class="iconfont header-abs-back">&#xe624;</div>
    </router-link>
    <div class="header-fixed" v-if="!isShow" :style="styleOpcaity">
      <router-link to="/" >
        <div class="iconfont header-fixed-icon">&#xe624;</div>
      </router-link>
      景点详情
    </div>
  </div>
</template>

<script>
export default {
    name:'DetailHeader',
    data () {
      return {
        isShow:true,
        styleOpcaity:{
          opacity :0
        }
      }
  },
  methods:{
    scrollTop (){
      console.log(1)
      const top = document.documentElement.scrollTop
      if(top>60){
        let opacity = top/140
        opacity = opacity>1?1:opacity
        this.styleOpcaity = {opacity}
        this.isShow = false
      }else{
        this.isShow = true
      }
    }
  },
  activated (){//keep-alive  提供的生命周期函数   页面加载一次就会执行一次
      window.addEventListener('scroll',this.scrollTop)//绑定在window上 所以会对其他所有组件造成影响  需要全局解绑
  },
  deactivated (){//页面即将被隐藏  或者页面即将被替换之后会执行
    window.removeEventListener('scroll',this.scrollTop)
  }
}
</script>

<style lang="stylus" scoped>
  @import "~styles/varibles.styl"
.header-abs
  position: absolute
  left: .2rem
  top: .2rem
  width: .8rem
  height: .8rem
  border-radius: .4rem
  background rgba(0,0,0,.8)
  text-align: center
  .header-abs-back
    color: #fff
    font-size:.4rem
    line-height:.8rem
.header-fixed
  z-index 2
  overflow: hidden
  height: $headerHeight
  line-height: $headerHeight
  text-align: center
  color #ffffff
  background :$bgColor
  font-size:.32rem
  position fixed
  top: 0
  left: 0
  right: 0
  .header-fixed-icon
    width .64rem
    text-align: center
    font-size: .4rem
    position absolute

    top: 0
    left: 0
    color: #fff
</style>
